<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>54数组扁平化、去重与排序</title>
</head>
<body>
<script>
  let arr = [40, 9, 20, 4, [1, 2, 3, 4], [2, 3, 4, [1, 2, 3, [1, 2, 3]], 5], [1, 2, 3, 4], [3, 4, 5, 9]]


  const flatten = (arr) => arr.reduce((prev, item) => prev.concat({}.toString.call(item) === '[object Array]' ? flatten(item) : item), [])


  function compare(a, b) {
    return a - b
  }


  console.log(Array.from(new Set(flatten(arr))).sort(compare));
</script>
</body>
</html>